package com.pan.test.socket.example04;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server04 {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(11451);
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String question = reader.readLine();
        System.out.println(question);
        String answer = "";
        if (question.equals("姓名？")){
            answer = "潘祺安";
        }else if (question.equals("性别?")){
            answer = "男";
        }else {
            answer = "你说啥？";
        }
        OutputStream outputStream = socket.getOutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream) );
        writer.write(answer);
        writer.newLine();
        writer.flush();
        socket.shutdownOutput();

        writer.close();
        outputStream.close();
        reader.close();
        inputStream.close();
        socket.close();
        serverSocket.close();

    }
}
